import {Component} from '@angular/core';
import {IonicPage, NavController, NavParams, ViewController} from 'ionic-angular';
import {WorkerProvider} from "@providers/interface/worker";
import {Util} from "@providers/util";
import {DialogProvider} from "@providers/dialog";

/**
 * Generated class for the PostersPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-posters',
  templateUrl: 'posters.html',
})
export class PostersPage {

  ID: any = this.navParams.data.ID;
  GDYYS: any;
  GDYY:any;
  BZ:any;

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private viewCtrl:ViewController,
              private dialog:DialogProvider,
              private worker: WorkerProvider,) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PostersPage'+this.ID);
    this.getGDYYS();

  }

  getGDYYS() {
    this.worker.selectGuaDan({}).then((datas) => {
      this.GDYYS = datas.data;
      console.log(datas.data);
    }).catch((error) => {
    })
  }

  subGD() {
    if(Util.isNull(this.GDYY)){
      return this.dialog.showAlert('请选择挂单原因');
    }
    this.worker.makeGuaDan({ID: this.ID, GDYY: this.GDYY,BZ:this.BZ}).then((message)=>{
      this.dialog.showAlert(JSON.stringify(message.MESSAGE));
      this.dismiss('s')
    }).catch((error)=>{

    })
  }

  dismiss(data?: any) {
    this.viewCtrl.dismiss(data);
  }

}
